using System.Collections.Generic;
using System.Linq;
using Dapper;
using Read.Models;

namespace Read.Services
{
    public class ArchivesService : BaseService
    {
        /// <summary>
        /// 获取文章列表
        /// </summary>
        /// <returns></returns>
        public List<ArchivesModel> getArchivesList()
        {
            using (var connection = GetConnection())
            {
                var sql = $"select Id,Title,CreateTime from `{Tables.Archives}`";
                var archiveslist = connection.Query<ArchivesModel>(sql).ToList();
                return archiveslist;
            }
        }

        /// <summary>
        /// 获取文章
        /// </summary>
        /// <returns></returns>
        public ArchivesModel getArchives(int Id)
        {
            using (var connection = GetConnection())
            {
                var sql = $"select * from `{Tables.Archives}` where Id=@Id";
                var archives = connection.QueryFirstOrDefault<ArchivesModel>(sql, new { Id = Id });
                return archives;
            }
        }
    }
}